package SEApp.dialogs
{
	import SEApp.se_util;
	
	import UIFree.components.uif_window;
	import UIFree.uif_component;
	
	import flash.events.Event;
	import flash.events.KeyboardEvent;
	import flash.events.MouseEvent;
	import flash.geom.Rectangle;
	
	public class se_buttonDialog extends se_dialog {
		protected var _button	: Object;
		protected var _cancel	: Object;
		public function se_buttonDialog(parent:uif_component, ax:int=0, ay:int=0, awidth:int=0, aheight:int=0, asModal:Boolean=false, canClose:int=2) {
			super(parent, ax, ay, awidth, aheight, asModal, canClose);
		}
		
		protected function createButtons(closeFunc: Function=null, cancelButton: Boolean = false): void {
			function closeEvent(e: Event): void {
				if (closeFunc != null) {
					function doCloseDialog(e: Event): void {
						removeEventListener(uif_window.CLOSEWINDOW, doCloseDialog);
						closeFunc();
					}
					addEvent(uif_window.CLOSEWINDOW, doCloseDialog);
				}
				doClose(e);
			}
			
			var inner: Rectangle = getInner();
			_button = se_util.defButton(this, 0, inner.height - se_util.DEFHEIGHTBUTTON, 'Оk', closeEvent);
				
			if (closeFunc != null) addEvent(KeyboardEvent.KEY_DOWN, function (e: KeyboardEvent): void {
				switch (e.keyCode) {
					case 17: closeEvent(e);
						break;
					case 13: close();
						break;
				}
			}, stage);
				
				
			if (cancelButton) {
				_cancel =  se_util.defButton(this, 0, inner.height - se_util.DEFHEIGHTBUTTON, 'Отмена', doClose);
				_button.x = inner.x + inner.width / 2 - _button.width - 2;
				_cancel.x = inner.x + inner.width / 2 + 2;
			} else _button.x = (inner.width - _button.width) / 2;
		}
			
		public function get okButton(): Object {
			return _button;
		}
		
		public function get cancelButton(): Object {
			return _cancel;
		} 
	}
}